#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#define inf 2147483647
using namespace std;

string s;
int g[105][105], n, l, rec[55][100005], f[55][100005];

int main()
{
	freopen("init.in", "r", stdin);
	//freopen("quicksum.out","w",stdout);
	cin >> s >> n;
	l = s.length();
	s = ' ' + s;
	for (int i = 1; i <= l; i++)
		g[i][i] = s[i] - '0';
	for (int i = 1; i <= l; i++)
		for (int j = i + 1; j <= l; j++)
		{
			g[i][j] = g[i][j - 1] * 10 + s[j] - '0';
			if (g[i][j] > inf)g[i][j] = inf;
		}
	for (int i = 0; i <= l; i++)
		for (int j = 0; j <= n; j++)
			rec[i][j] = inf;
	rec[0][0] = 0;
	f[0][0] = 1;
	for (int i = 1; i <= l; i++)
		for (int j = 1; j <= i; j++)
		{
			if (g[i - j + 1][i] > n)
				break;
			for (int k = 0; k <= n; k++)
				if (f[i - j][k])
				{
					if (k + g[i - j + 1][i] > n)
						break;
					f[i][k + g[i - j + 1][i]] = 1;
					rec[i][k + g[i - j + 1][i]] = min(rec[i][k + g[i - j + 1][i]], rec[i - j][k] + 1);
				}
		}
	if (rec[l][n] == inf)
		cout << -1 << endl;
	else
		cout << rec[l][n] - 1 << endl;
	return 0;
}